import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';

const baseUrl = '/afterSales/api/v1';

const initDesc = formatMessage({
    id: 'api.message.initDesc',
    defaultMessage: '初始化界面'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询二次索赔汇总单'
});
const newOrderDesc = formatMessage({
    id: 'api.message.newOrderDesc',
    defaultMessage: '生成二次索赔汇总单'
});
const deliveryListDesc = formatMessage({
    id: 'api.message.deliveryListDesc',
    defaultMessage: '导出送单清单'
});
const costSumExcelDesc = formatMessage({
    id: 'api.message.costSumExcelDesc',
    defaultMessage: '导出费用汇总'
});
const sumTableExcelDesc = formatMessage({
    id: 'api.message.sumTableExcelDesc',
    defaultMessage: '导出汇总表'
});
const supplierSumExcelDesc = formatMessage({
    id: 'api.message.supplierSumExcelDesc',
    defaultMessage: '导出供应商汇总'
});
//初始化品牌
import {baseDataStatus} from '../Enum';
export const getInitData = () => {
    const queryString = stringify({
        status: baseDataStatus.生效
    });
    return request(`${baseUrl}/ui/secondClaimSummary/init?${queryString}`, null, dto.InitDataStruct)
        .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, initDesc));
};
// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/secondClaimSummaries?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询订单列表
export const newOrder = data => request(`${baseUrl}/secondClaimSummaries/create`, {
    method: 'POST',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, newOrderDesc));

// 导出送单清单
export const deliveryList = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/secondClaimSummaries/deliveryListExcel?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, deliveryListDesc))
        .then(res => res.data);
};
// 导出费用汇总
export const costSumExcel = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/secondClaimSummaries/costSumExcel?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, costSumExcelDesc))
        .then(res => res.data);
};
// 导出汇总表
export const sumTableExcel = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/secondClaimSummaries/sumTableExcel?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, sumTableExcelDesc))
        .then(res => res.data);
};
// 导出供应商汇总
export const supplierSumExcel = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/secondClaimSummaries/supplierSumExcel?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, supplierSumExcelDesc))
        .then(res => res.data);
};
